import {
    getRzrygw,
    getRzrygb,
    getZdlz,
    getLzl,
    getBdlz,
    getZztgl,
    getZzyql,
    getTgrytj,
    getRyzs
} from '@/services/personnel';

export default {
    namespace: 'personnel',
    state: {
        ryzs: {
            desc: '',
            list: []
        }, // 人员走势
        rzrygw: [
            {
                name: '人事岗',
                value: 6,
                children: [
                    { name: ' 人事岗1', value: 2 },
                    { name: '人事岗2', value: 4 }
                ]
            },
            {
                name: '行政职位',
                value: 6,
                children: [
                    { name: ' 行政职位1', value: 2 },
                    { name: '行政职位2', value: 4 }
                ]
            }
        ],
        rzrygb: [],
        lzl: [], // 离职率
        zztgl: [], // 转正通过率
        zzyql: [], // 转正延期率
        tgrytj: [], // 调岗人员统计
        zdlz: [
            { name: '家庭原因', value: 1 },
            { name: '其他', value: 2 },
            { name: '薪资原因', value: 3 }
        ], // 主动离职
        bdlz: [
            { name: '违法', value: 1 },
            { name: '态度', value: 2 },
            { name: '时间', value: 3 }
        ] // 被动离职
    },
    effects: {
        *fetchRyzs({ payload }, { call, put }) {
            const result = yield call(getRyzs, payload);
            if (result && result.code === 10000) {
                yield put({
                    type: 'save',
                    payload: {
                        ryzs: result.data
                    }
                });
            }
        },
        // 新入职人员分析
        *fetchAllEntry({ payload }, { put, all }) {
            console.log('payloadEntry', payload);
            yield all([
                put({
                    type: 'fetchRzrygb',
                    payload
                }),
                put({
                    type: 'fetchRzrygw',
                    payload
                })
            ]);
        },
        *fetchRzrygb({ payload }, { put, call }) {
            const result = yield call(getRzrygb, payload);
            if (result && result.code === 10000) {
                yield put({
                    type: 'save',
                    payload: {
                        rzrygb: result.data.children
                    }
                });
            }
        },
        *fetchRzrygw({ payload }, { call, put }) {
            const result = yield call(getRzrygw, payload);
            if (result && result.code === 10000) {
                yield put({
                    type: 'save',
                    payload: {
                        rzrygw: result.data
                    }
                });
            }
        },
        // 离职统计分析
        *fetchAllLeave({ payload }, { put, all }) {
            console.log('payloadleave', payload);
            yield all([
                put({
                    type: 'fetchLzl',
                    payload
                }),
                put({
                    type: 'fetchZdlz',
                    payload
                }),
                put({
                    type: 'fetchBdlz',
                    payload
                })
            ]);
        },
        *fetchLzl({ payload }, { put, call }) {
            const result = yield call(getLzl, payload);
            if (result && result.code === 10000) {
                yield put({
                    type: 'save',
                    payload: {
                        lzl: result.data
                    }
                });
            }
        },
        *fetchZdlz({ payload }, { call, put }) {
            const result = yield call(getZdlz, payload);
            if (result && result.code === 10000) {
                yield put({
                    type: 'save',
                    payload: {
                        zdlz: result.data
                    }
                });
            }
        },
        *fetchBdlz({ payload }, { call, put }) {
            const result = yield call(getBdlz, payload);
            if (result && result.code === 10000) {
                yield put({
                    type: 'save',
                    payload: {
                        bdlz: result.data
                    }
                });
            }
        },
        *fetchZztgl({ payload }, { put, call }) {
            const result = yield call(getZztgl, payload);
            if (result && result.code === 10000) {
                yield put({
                    type: 'save',
                    payload: {
                        zztgl: result.data
                    }
                });
            }
        },
        *fetchZzyql({ payload }, { put, call }) {
            const result = yield call(getZzyql, payload);
            if (result && result.code === 10000) {
                yield put({
                    type: 'save',
                    payload: {
                        zzyql: result.data
                    }
                });
            }
        },
        // 转正人员分析
        *fetchAllRegular({ payload }, { put, all }) {
            yield all([
                put({
                    type: 'fetchZztgl',
                    payload
                }),
                put({
                    type: 'fetchZzyql',
                    payload
                })
            ]);
        },
        *fetchTgrytj({ payload }, { put, call }) {
            const result = yield call(getTgrytj, payload);
            if (result && result.code === 10000) {
                yield put({
                    type: 'save',
                    payload: {
                        tgrytj: result.data
                    }
                });
            }
        }
    },
    reducers: {
        save(state, { payload }) {
            return {
                ...state,
                ...payload
            };
        },
        clear() {
            return {
                ryzs: {
                    desc: '',
                    list: []
                }, // 人员走势
                rzrygb: [],
                rzrygw: [],
                lzl: [], // 离职率
                zdlz: [], // 主动离职
                bdlz: [], // 被动离职
                zztgl: [], // 转正通过率
                zzyql: [], // 转正延期率
                tgrytj: [] // 调岗人员统计
            };
        }
    }
};
